<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;


/**
 * App\Models\Collect
 *
 * @property int $id
 * @property int $uid
 * @property int $dataid
 * @property string $datatype
 * @property string $title
 * @property string $image
 * @property string $created_at
 * @property string $updated_at
 * @property-read \App\Models\Item $item
 * @property-read \App\Models\PostItem $post
 * @property-read \App\Models\Shop $shop
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Collect whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Collect whereDataid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Collect whereDatatype($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Collect whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Collect whereImage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Collect whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Collect whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Collect whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Collect extends Model
{
    protected $table = 'collect';
    protected $primaryKey = 'id';
    protected $guarded = ['id'];

    public $timestamps = false;

    public static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        static::creating(function ($model){
            $model->created_at = time();
            $model->updated_at = time();
        });

        static::updating(function ($model){
            $model->updated_at = time();
        });
    }

    public function item()
    {
        return $this->belongsTo(Item::class, 'dataid', 'itemid');
    }

    public function post()
    {
        return $this->belongsTo(PostItem::class, 'dataid', 'aid');
    }

    public function shop()
    {
        return $this->belongsTo(Shop::class, 'dataid', 'shop_id');
    }
}
